package lab02.test06;

import static java.lang.StrictMath.sqrt;

//定义三角形的三条边，面积，周长，以及一个布尔型来判断三角形时候否成立
public class Triangle {
   private float oneside;
   private float twoside;
   private float threeside;
   private double area;
   private double perimeter;
   private boolean triangle;
   //构造空参
    public Triangle(float oneside,float twoside,float threeside){
        this.oneside= oneside;
        this.twoside = twoside;
        this.threeside = threeside;
    }
//通过set,get方法来获取三条边张
    public void setOneside(float oneside) {
        this.oneside = oneside;
    }

    public float getOneside() {
        return oneside;
    }

    public void setTwoside(float twoside) {
        this.twoside = twoside;
    }

    public float getTwoside() {
        return twoside;
    }

    public void setThreeside(float threeside) {
        this.threeside = threeside;
    }

    public float getThreeside() {
        return threeside;
    }
    //判断三条边是否满足构成三角形
    public boolean triangle(){
        if(oneside+twoside>=threeside&&oneside+threeside>=twoside){
            if(twoside+threeside>=oneside){
                return triangle = true;
            }
            else {
                return triangle = false;
            }
        }
        return  triangle = false;
    }
    //  求三角形的周长
    public double Perimeter(){
        double perimeter =oneside+twoside+threeside;
        return  perimeter;
    }
    //  求三角形的面积，只知道三边，用海伦公式求解
    public double Area(){
        double p = (oneside+twoside+threeside)/2;
        return area =sqrt(p*(p-oneside)*(p-twoside)*(p-threeside));
    }
}
